﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hxj.Data;
using Utility;
using MsgCenter.DAL.Base;
using Utility.Model;

namespace MsgCenter.BLL.Impl
{
    /// <summary>
    /// 功能管理业务层
    /// </summary>
    public class BLL_SysOperate
    {
        private readonly BaseService dal = new BaseService();
        /// <summary>
        /// 保存修改
        /// </summary>
        /// <param name="model">对象实体</param>
        public void Save(Sys_Operate model)
        {
            DbTrans trans = dal.GetDataBase().BeginTransaction();
            try
            {
                dal.Save<Sys_Operate>(model, trans);
                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                throw ex;
            }
            finally
            {
                trans.Close();
            }
        }
        /// <summary>
        /// 删除,修改状态
        /// </summary>
        /// <param name="strDataID">数据ID</param>
        public void Delete(string strDataID)
        {
            if (strDataID.Length > 0)
            {
                string[] idList = strDataID.Trim(',').Split(',');
                DbTrans trans = dal.GetDataBase().BeginTransaction();
                try
                {
                    foreach (string strOperateID in idList)
                    {
                        dal.ExecuteNonQuery("Update Sys_Operate set Isdelete=1 where OperateID='" + strOperateID + "'", trans);
                    }
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
                finally
                {
                    trans.Close();
                }
            }
        }
        /// <summary>
        /// 获取对象实体
        /// </summary>
        /// <param name="id">数据ID</param>
        /// <returns>Sys_Operate</returns>
        public Sys_Operate GetModel(string id)
        {
            return dal.GetModel<Sys_Operate>(Sys_Operate._.OperateID == id);
        }
        /// <summary>
        /// 保存默认空值,对应外键
        /// </summary>
        public void SaveStartNull()
        {
            if (GetModel(Guid.Empty.ToSafeString()) == null)
            {
                Save(new Sys_Operate() { OperateID = Guid.Empty.ToSafeString(), OperateName = "默认空值", OperateValue = "btnNull", IsDelete = true });
            }
        }
    }
}
